/*
 * lfs_protocol.h
 *
 *  Created on: Jan 13, 2013
 *      Author: redchen
 */

#ifndef LFS_PROTOCOL_H_
#define LFS_PROTOCOL_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <lfs.h>
#include <buffer.h>

int lfs_protocol_deserialize(const char* method, Buffer* req, Buffer* resp_data, void** input, void** output);

int lfs_protocol_serialize(const char* method, void* input, void* output, Buffer* req, Buffer* resp);

typedef struct {
    char filename[FILENAME_LEN];
    int32_t min_replica;
    int32_t max_replica;
}FileCreateRequest;

typedef struct {
    Status status;
}FileCreateResponse;

void file_create_request_serialize(FileCreateRequest* request, Buffer* buf);
void file_create_request_deserialize(Buffer* buf, FileCreateRequest* request);

void file_create_response_serialize(FileCreateResponse* response, Buffer* buf);
void file_create_response_deserialize(Buffer* buf, FileCreateResponse* response);

typedef struct {
    char filename[FILENAME_LEN];
    int32_t size;
} FileWriteRequest;

typedef struct {
    Status status;
    int64_t id;
} FileWriteRespoonse;

void file_write_request_serialize(FileWriteRequest* request, Buffer* buf);
void file_write_request_deserialize(Buffer* buf, FileWriteRequest* request);

void file_write_response_serialize(FileWriteRespoonse* response, Buffer* buf);
void file_write_response_deserialize(Buffer* buf, FileWriteRespoonse* response);

typedef struct {
    char filename[FILENAME_LEN];
    int64_t id;
    int32_t size;
}AddChunkRequest;

typedef struct {
    Status status;
}AddChunkResponse;

void add_chunk_request_serialize(AddChunkRequest* request, Buffer* buf);
void add_chunk_request_deserialize(Buffer* buf, AddChunkRequest* request);

void add_chunk_response_serialize(AddChunkResponse* response, Buffer* buf);
void add_chunk_response_deserialize(Buffer* buf, AddChunkResponse* response);


#ifdef __cplusplus
}
#endif


#endif /* LFS_PROTOCOL_H_ */
